﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Common.OA.DailyReport;
using BCService.CommonService.OA.DailyReport;
using BlackCoffeeRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BlackCoffeeRESTful.Controllers.Management.OA
{
    /// <summary>
    /// 日报服务接口
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class DailyReportController : ManagementBaseController
    {
        private readonly IDailyReportService dailyReportService;

        public DailyReportController(IDailyReportService dailyReportService)
        {
            this.dailyReportService = dailyReportService;
        }

        #region 创建一条日报信息
        /// <summary>
        /// 创建一条日报信息
        /// </summary>
        /// <param name="dailyReportRequestDto">日报创建请求模型</param>
        /// <response code="200">新创建的日报信息</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建一条日报信息")]
        [ProducesResponseType(typeof(DailyReportDto), 200)]
        public IActionResult Post([FromBody] DailyReportRequestDto dailyReportRequestDto)
        {

            var dailyReport = this.dailyReportService.Create(this.Admin, dailyReportRequestDto);

            return Ok(dailyReport);
        }
        #endregion

        #region 修改一条日报信息

        /// <summary>
        /// 修改日报信息
        /// </summary>
        /// <param name="dailyReportNo">日报Id</param>
        /// <param name="dailyReportSimPutDto">日报修改请求模型</param>        
        /// <returns></returns>
        /// <response code="200">修改后的日报信息。</response>
        [HttpPut("{daily_report_no}")]
        [Log("修改日报信息")]
        [ProducesResponseType(typeof(DailyReportDto), 201)]
        public IActionResult Put([FromRoute(Name = "daily_report_no")] string dailyReportNo, [FromBody] DailyReportSimPutDto dailyReportSimPutDto)
        {

            return this.Ok(this.dailyReportService.Update(dailyReportNo, dailyReportSimPutDto));
        }

        #endregion

        #region 删除一条日报信息
        /// <summary>
        /// 删除一条日报信息
        /// </summary>
        /// <param name="dailyReportNo">日报Id</param>
        /// <returns></returns>
        /// <response code="204">刪除一条日报信息成功。</response>
        [HttpDelete("{daily_report_no}")]
        [Log("删除一条日报信息")]
        public IActionResult Delete([FromRoute(Name = "daily_report_no")] string dailyReportNo)
        {
            this.dailyReportService.Delete(dailyReportNo);
            return NoContent();
        }
        #endregion

        #region 获取一条日报信息
        /// <summary>
        /// 获取一条日报信息
        /// </summary>
        /// <param name="dailyReportNo">日报ID</param>
        /// <returns></returns>
        [HttpGet("{daily_report_no}")]
        [ProducesResponseType(typeof(DailyReportDto), 200)]

        public IActionResult Get([FromRoute(Name = "daily_report_no")] string dailyReportNo)
        {
            return Ok(this.dailyReportService.Get(dailyReportNo));
        }

        #endregion

        #region 获取日报信息接口（分页）
        /// <summary>
        /// 获取日报信息列表（分页）
        /// </summary>
        /// <param name="adminFullName">员工姓名</param>
        /// <param name="idCard">身份证</param>
        /// <param name="phone">手机号</param>
        /// <param name="adminId">员工ID</param>
        /// <param name="isRead">是否阅读</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>       
        /// <param name="ascending">排序</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">带有分页信息的日报列表。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<DailyReportInfoDto>), 200)]
        public IActionResult List([FromQuery(Name = "user_name")] string adminFullName,
            [FromQuery(Name = "id_card")] string idCard,
            [FromQuery(Name = "phone")] string phone,
            [FromQuery(Name = "admin_id")] long? adminId,
            [FromQuery(Name = "is_read")] bool? isRead,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "ascending")] bool? ascending,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var list = this.dailyReportService.List(adminFullName, idCard, phone, adminId, isRead, start, end, ascending, pageIndex, pageSize);
            return this.Ok(list);
        }
        #endregion

        #region 主管已阅读操作

        /// <summary>
        /// 主管已阅读操作
        /// </summary>
        /// <param name="dailyReportNo">日报编号</param>      
        /// <returns></returns>
        /// <response code="200">修改后的日报信息。</response>
        [HttpPut("[action]/{daily_report_no}")]
        [Log("主管已阅读操作")]
        [ProducesResponseType(typeof(DailyReportDto), 200)]
        public IActionResult UpdateRead(string dailyReportNo)
        {
            return Ok(this.dailyReportService.UpdateRead(dailyReportNo));
        }

        #endregion
    }
}